/*
 * @Author: csy
 *  主管报表
 * @Date: 2019-04-15 14:44:57 
 * @Last Modified by: csy
 * @Last Modified time: 2019-04-15 14:44:57
 */
layui.config({}).use(['element', 'zlConfig','zltreemenu', 'zlContext', 'table', 'layer', 'form'], function (exports) {
	var $ = layui.$,
		zlContext = layui.zlContext,
		layer = layui.layer,
		table = layui.table,
        form = layui.form,
        zltreemenu = layui.zltreemenu,
		zlConfig = layui.zlConfig,
		statusName = zlConfig.global.result.statusName,
		msgName = zlConfig.global.result.msgName,
		dataName = zlConfig.global.result.dataName,
        OK = zlConfig.global.result.okState,
        curUserVo = zlContext.getCurrentUser(),
        gFrReportIframe,
        zlReportArgments = {},
        fullheight = 'full-40';

    var tableObj, 
        fromlayerIndex,
        frIframeReloadIndex,
        nodeReportAuditStatus = {};
	//渲染用户列表
	tableObj = table.render({
		elem: '#tbDirectorReport',
		height: fullheight,
		response: zlConfig.global.gridResponse,
		limit: 999,
        page: false,
        where: {
            "ORGID": curUserVo["currentOrgId"]
        },
		url: layui.cache['contentPath'] + "/manager/coreauditreport/reportlist",
		method: 'post',
		sortload: true,
		cols: [
			[ //表头
				{
					type: 'numbers',
					fixed: 'left',
					title: '#'
				}, {
					field: 'OBJNAME',
                    title: '报表名称',
                    width: '45%',
					sort: true
				}, {
					field: 'JIZR',
                    title: '基准日',
                    width: '25%',
					sort: true
				}, {
					field: 'SYS_AUDFLAG',
					title: '流程状态',
					unresize: true,
					templet: function (d) {
                        if("0" == d.SYS_AUDFLAG){
                            return "待处理";
                        }else if("1" == d.SYS_AUDFLAG){
                            return "已提交";
                        }else if("2" == d.SYS_AUDFLAG){
                            return "审核通过";
                        }else if("3" == d.SYS_AUDFLAG){
                            return "退回";
                        }else {
                            return "错误状态";
                        }
					}
				}, {
					fixed: 'right',
					width: 180,
					title: '操作',
					align: 'center',
					toolbar: '#barDirectorReport'
				}
			]
		],
		event: {
			onRowdbClick: function (field, row) {
				gridAction.editRow(row);
			}
		}
	});

	var gridAction = {
        currentEditObj: undefined,
        orgtreeObj: undefined,
        curOrgNodeReport: undefined,
        curOrgTreeNode: undefined,
		orgReportGridedit: function (row, type, readonly) {
			var readonly = readonly && readonly != 0 ? 'disabled' : '';
			var frm = [
                '<div class="layui-fluid">',
                '    <div class="layui-row  layui-col-space5">',
                '        <div class="layui-col-md2 docking-left">',
                '           <div class="layui-card docking-left">',
                '               <div class="layui-card-body zltree-body">',
                '                   <input type="hidden" name="ORGIDTEMP">',
                '                   <ul id="orgtree" class="ztree"></ul>',
                '               </div>',
                '           </div>',
                '       </div>',
                '       <div class="layui-col-md10 docking-fill">',
                '           <div class="layui-card">',
                '               <div class="layui-card-body">',
                '                   <div class="zl-toolbar">',
                '                   </div>',
                '                   <div class="zl-container">',
                '                       <div id="zl-reportFrame-container" class="zl-container">',
                '                           <form id="frm-reportFrame" action="" target="target-reportFrame" method="post">',
                '                               <input type="hidden" name="USERID" />',
                '                               <input type="hidden" name="ORGID" />',
                '                               <input type="hidden" name="DEPTID" />',
                '                               <input type="hidden" name="ROLEID" />',
                '                               <input type="hidden" name="ROLECODE" />',
                '                               <input type="hidden" name="RPT_ID" />',
                '                           </form>',
                '                           <iframe id="reportFrame" name="target-reportFrame" width =100% height =100%></iframe>',
                '                       </div>',
                '                   </div>',
                '               </div>',
                '           </div>',
                '       </div>',
                '   </div>',
                '</div>'
            ];
			layer.open({
				type: 1,
				limit: 999,
				title: "机构填报",
				id: 'coreZgReportLayer',
				area: ['100%', '100%'],
				content: frm.join(''),
				success: function (layero, index) {
                    fromlayerIndex = index;
                    setMaxHeihgt(10,30);
                    //获取报表审核状态
                    zlContext.asyncGet(layui.cache['contentPath'] + "/manager/coreauditreport/querystatus",{"SYS_PARENTID": row["ORGID"],"RPT_JZR_ID":row["RPT_JZR_ID"]},function(result){
                        if(result[statusName] == OK){
                            if(result[dataName]){
                                nodeReportAuditStatus = result[dataName];
                            }
                        }
                    },false);
                    //加载机构树
                    gridAction.orgtreeObj = zltreemenu.render('orgtree', {
                        dataurl: layui.cache['contentPath'] + "/manager/corefunction/queryorgddata?resId=8B3E065550624EE798258B73D13A7C5F",
                        type: "get",
                        isMove: false,
                        fontCss: function(treeId, treeNode){
                            if(treeNode.level == 1){
                                var state = nodeReportAuditStatus[treeNode["RWID"]];
                                if(1 == state){
                                    //提交
                                    return {"color": "#99fb98"}
                                }else if(2 == state){
                                    //审核
                                    return {"color": "#01ffff"}
                                }else{
                                    return {"color": "#ff5722"};
                                }
                            }
                            }
                        }, {
                        onAsyncSuccess: function (event, treeId, treeNode, msg) {
                            var rootNode = gridAction.orgtreeObj.getNodes()[0];
                            gridAction.orgtreeObj.selectNode(rootNode);
                            $('#' + rootNode.tId + '_a').click();
                            if(nodeReportAuditStatus && rootNode["children"]){
                                var arrChildren = rootNode["children"];
                                for(var i = 0; i < arrChildren.length;i++){
                                    var node = arrChildren[i];

                                }
                            }
                        },
                        onClick: function (event, treeId, treeNode) {
                            //选择机构树节点事件
                            gridAction.curOrgNodeReport = undefined;
                            frIframeReloadIndex = layer.msg('数据查询中，请稍候...', {icon: 16, time: false,shade: 0.1 });
                            $('input[name="ORGIDTEMP"]').val(treeNode.RWID);
                            //判断是否为当前机构
                            gridAction.curOrgTreeNode = treeNode;

                            if(treeNode.RWID == gridAction.currentEditObj.data["ORGID"]){
                                //编辑状态
                                gridAction.curOrgNodeReport = gridAction.currentEditObj.data;
                                gridAction.editHeaderBtn(treeNode);
                                gridAction.onBeforeLoadFrReportIframe();
                                gridAction.onLoadFrReportIframe(gridAction.curOrgNodeReport);
                            }else{
                                gridAction.curOrgNodeReport = reportAction.getOrgReport({"ORGID": treeNode.RWID,"JIZR": gridAction.currentEditObj.data['JIZR']});
                                //修改树节点颜色
                                nodeReportAuditStatus[gridAction.curOrgNodeReport["ORGID"]] = gridAction.curOrgNodeReport["SYS_AUDFLAG"];
                                gridAction.orgtreeObj.updateNode(treeNode);
                                if(!gridAction.curOrgNodeReport || (1 != gridAction.curOrgNodeReport.SYS_AUDFLAG && 2 != gridAction.curOrgNodeReport.SYS_AUDFLAG)){
                                    $("#coreZgReportLayer .zl-toolbar").empty();
                                    $("#reportFrame").attr("src", layui.cache['contentPath'] + "/manager/coreauditreport/noreport?msg=无报表数据");
                                    gridAction.onAfterLoadFrReportIframe();
                                }else{
                                    gridAction.editHeaderBtn(treeNode);
                                    gridAction.onBeforeLoadFrReportIframe();
                                    gridAction.onLoadFrReportIframe(gridAction.curOrgNodeReport);
                                }
                            }
                        }
                    });
				}
			});
        },
        editHeaderBtn: function(orgNode){
            //编辑头部按钮
            var curReport = gridAction.curOrgNodeReport;
            $("#coreZgReportLayer .zl-toolbar").addClass("layui-hide").empty();
            if(curReport["RWID"] == gridAction.currentEditObj.data["RWID"]){
                //当前为主管节点
                if(curReport["SYS_AUDFLAG"] == 1 || curReport["SYS_AUDFLAG"] == 2){
                    //已提交
                    $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                       .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>')
                                                       .append('<button class="layui-btn layui-btn-sm show-process-log"><i class="layui-icon layui-icon-form"></i>查看流程状态</button>');
                }else{
                    $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportSave layui-hide"><i class="layui-icon layui-icon-form"></i>保存</button>')
                                                       .append('<button id="btnReportInit" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-table"></i>提取数据</button>')
                                                       .append('<button class="layui-btn layui-btn-sm btnReportAdd layui-hide"><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>')
                                                       .append('<button class="layui-btn layui-btn-sm btnReportDelete layui-hide"><i class="layui-icon layui-icon-delete"></i>删除</button>')
                                                       .append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                       .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>');
                    
                    if(gridAction.currentEditObj.data["coreRptJzr"] && gridAction.currentEditObj.data.coreRptJzr["ORGID"] != gridAction.currentEditObj.data["ORGID"]){
                        $("#coreZgReportLayer .zl-toolbar").append('<button id="btnReportSubmit" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-form"></i>提交</button>');
                    }
                }
            }else{
                //下级机构节点
                if(orgNode["SYS_PARENTID"] == gridAction.currentEditObj.data["ORGID"]){
                    //直属下级
                    if(curReport["SYS_AUDFLAG"] == 1){
                        //未审批
                        $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                           .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>')
                                                           .append('<button id="btnReportAudit" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-form"></i>审核</button>')
                                                           .append('<button class="layui-btn layui-btn-sm show-process-log"><i class="layui-icon layui-icon-form"></i>查看流程状态</button>');
                    }else if(curReport["SYS_AUDFLAG"] == 2){
                        //已审批
                        if(gridAction.currentEditObj.data["SYS_AUDFLAG"] == 1 || gridAction.currentEditObj.data["SYS_AUDFLAG"] == 2){
                            //主管已提交
                            $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                               .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>')
                                                               .append('<button class="layui-btn layui-btn-sm show-process-log"><i class="layui-icon layui-icon-form"></i>查看流程状态</button>');
                        }else{
                            //主管未提交
                            $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                               .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>')
                                                               .append('<button id="btnReportBack" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-form"></i>退回</button>')
                                                               .append('<button class="layui-btn layui-btn-sm show-process-log"><i class="layui-icon layui-icon-form"></i>查看流程状态</button>');
                        }
                    }
                }else{
                    //非直属下级
                    if(curReport["SYS_AUDFLAG"] == 1 || curReport["SYS_AUDFLAG"] == 2){
                        //非直属下级，只能查看已审核状态
                        $("#coreZgReportLayer .zl-toolbar").append('<button class="layui-btn layui-btn-sm btnReportPrint"><i class="layui-icon layui-icon-print"></i>打印</button>')
                                                           .append('<button class="layui-btn layui-btn-sm btnReportExport"><i class="layui-icon layui-icon-print"></i>导出</button>')
                                                           .append('<button class="layui-btn layui-btn-sm show-process-log"><i class="layui-icon layui-icon-form"></i>查看流程状态</button>');
                    }
                }
            }
            //绑定事件
            $("#coreZgReportLayer .zl-toolbar .btnReportPrint").on("click",function(){
                //打印
                reportAction.printReport();
            });
             $("#coreZgReportLayer .zl-toolbar .btnReportExport").on("click",function(){
                //导出
                reportAction.exportReport();
            });
             $("#coreZgReportLayer .zl-toolbar .show-process-log").on("click",function(){
                //查看流程日志
                reportAction.showProcessLog();
            });
            $("#coreZgReportLayer .zl-toolbar .btnReportAdd").on("click",function(){
                //增加行
                reportAction.addReport();
            });
            $("#coreZgReportLayer .zl-toolbar .btnReportDelete").on("click",function(){
                //删除行
                reportAction.deleteReport();
            });
            $("#coreZgReportLayer .zl-toolbar .btnReportSave").on("click",function(){
                //保存
                reportAction.saveCurReport();
            });
            $("#coreZgReportLayer .zl-toolbar #btnReportInit").on("click",function(){
                //初始化
                reportAction.initReport();
            });
            $("#coreZgReportLayer .zl-toolbar #btnReportSubmit").on("click",function(){
                //提交
                reportAction.submitReport();
            });
            $("#coreZgReportLayer .zl-toolbar #btnReportAudit").on("click",function(){
                //审批
                reportAction.auditReport();
            });
            $("#coreZgReportLayer .zl-toolbar #btnReportBack").on("click",function(){
                //退回
                reportAction.backReport();
            });
        },
		editRow: function (row) {
            if(row["REPORT_ID"] && row["report"] && row.report["REP_LUJ"]){
                var type = ( 1 == row["SYS_AUDFLAG"] || 2 == row["SYS_AUDFLAG"] ? "view" : "write");
                var readonly = ( "view" == type ? "readonly" : "");
                gridAction.orgReportGridedit(row, type, readonly);
            }else{
                zlContext.errorMsg("无法获取报表模板");
            }
        },
        onBeforeLoadFrReportIframe: function(){
            //加载帆软报表前调用：主要用于设置请求参数等
            $('#frm-reportFrame input[name="USERID"]').val(curUserVo["id"]);
            $('#frm-reportFrame input[name="ORGID"]').val(curUserVo["currentOrgId"]);
            $('#frm-reportFrame input[name="DEPTID"]').val(curUserVo["currentDeptId"]);
            $('#frm-reportFrame input[name="ROLEID"]').val(curUserVo["currentRoleId"]);
            $('#frm-reportFrame input[name="ROLECODE"]').val(curUserVo["currentRoleCode"]);
            $('#frm-reportFrame input[name="RPT_ID"]').val(gridAction.currentEditObj.data["RWID"]);
        },
        onLoadFrReportIframe: function(rptReport, type, readonly){
            //修改请求URL加载帆软报表
            var frUrl = rptReport.report["REP_LUJ"];
            if("write" == type){
                frUrl = frUrl.replace("op=view","op=write");
            }else{
                frUrl = frUrl.replace("op=write","op=view");
            }
            frIframeReloadIndex = layer.msg('数据查询中，请稍候...', {icon: 16, time: false,shade: 0.1 });
            //表单提交加载报表
            $("#frm-reportFrame").attr("action",frUrl);
            $("#frm-reportFrame").submit();
            //设置报表回调
            gFrReportIframe = document.getElementById('reportFrame');
            gFrReportIframe.onload = gFrReportIframe.onreadystatechange = gridAction.onAfterLoadFrReportIframe;
        },
        onAfterLoadFrReportIframe: function(){
            //显示按钮
            $("#coreZgReportLayer .zl-toolbar").removeClass("layui-hide");
            //加载完帆软报表后回调：用于关闭遮罩等
            layer.close(frIframeReloadIndex);
		},
        reloadFrReportIframe: function(report){
            var frReportUrl = report.coreRptJzr["REPORT_URL"];
            if(1== report.SYS_AUDFLAG || 2 == report.SYS_AUDFLAG){
                frReportUrl = frReportUrl.replace("op=write","op=view");
            }else{
                frReportUrl = frReportUrl.replace("op=view","op=write");
            }
            $("#reportFrame").attr("src", frReportUrl);
        },
        onFrReportIframeLoad: function(){
            layer.close(frIframeReloadIndex);
		},
		search: function () {
			layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, null);
		}
    }
    
    //报表操作
    var reportAction = {
        printReport: function(args){
            gFrReportIframe.contentWindow.contentPane.noClientPrint();
        },
        exportReport: function(args){
            zlContext.errorMsg("打印接口未实现");
        },
        showProcessLog: function(args){
            var row = gridAction.curOrgNodeReport;
            if(!row.SYS_AUDFLAG || row.SYS_AUDFLAG == 0 || !row.SYS_PID){
                zlContext.warnMsg('流程未启动');
                return;
            }
            var params = {
                "SYS_PID": row["SYS_PID"]
            }
            zlContext.post(layui.cache['contentPath'] + '/manager/coreauditreport/query/processlog', params, function (data) {
                var html = [
                            '<div class="layui-row">', 
                            '	<div class="layui-col-md12 docking-fill"><div class="layui-card-body">', 
                            '		<table id="tbFindWorkflow" class="layui-hide" lay-filter="tbWorkflow"></table>', 
                            '	</div></div>', 
                            '</div>'
                            ]
                layer.open({
                    type: 1,
                    title: '查看流程',
                    id: 'checkProcessLayer',
                    area: ['100%', '100%'],
                    content: html.join(''),
                    response: zlConfig.global.gridResponse,
                    success: function (layero, index) {
                        table.render({
                            elem: '#tbFindWorkflow',
                            height: 'full-65',
                            page: false,
                            sortload: false,
                            cols: [
                                [ //表头
                                    {
                                        type: 'numbers',
                                        fixed: 'left',
                                        title: '#'
                                    }, {
                                        field: 'NAME_ROLE',
                                        title: '审核人',
                                        width: '40%',
                                        sort: true
                                    }, {
                                        field: 'ORG_NAME',
                                        title: '机构名称',
                                        width: 300,
                                        sort: true
                                    }, {
                                        field: 'SYS_CREATETIME',
                                        title: '审核时间',
                                        width: 200,
                                        sort: true
                                    }, {
                                        field: 'USER_OPERATE',
                                        title: '操作',
                                        width: 200,
                                        sort: true
                                    }, {
                                        field: 'MESSAGE',
                                        title: '审核意见',
                                        sort: true
                                    }
                                ]
                            ],
                            data: data.obj,
                        });
                    }
                });
            });
        },
        getOrgReport: function(args){
            //点击机构树节点，查看机构报表
            var retObj;
            zlContext.asyncGet(layui.cache['contentPath'] + "/manager/coreauditreport/query",args,function(result){
                if (result[statusName] == OK) {
                    retObj = result[dataName];
                }else{
                    //跳转
                    zlContext.errorMsg(result[msgName]);
                }
            },true);
            return retObj;
        },
        addReport: function (args) {
			gFrReportIframe.contentWindow.contentPane.appendReportRC(1);
        },
        deleteReport: function (args) {
			gFrReportIframe.contentWindow.contentPane.deleteReportRC();
        },
        saveCurReport: function(args){
            gFrReportIframe.contentWindow.contentPane.verifyAndWriteReport();
        },
        initReport: function(args){
            var row = gridAction.currentEditObj.data;
            var iframeDoc = document.getElementById('reportFrame').contentWindow.document;
            var $ifameDoc = $(iframeDoc);
            var sheetIndex = $ifameDoc.find(".fr-sheetbutton-container").index($ifameDoc.find(".fr-sheetbutton-container-active"));
            var params = {
                "RWID":row["RWID"],
                "sheetIndex":sheetIndex
            }
            params = $.extend(params, zlReportArgments);
            zlContext.confirm('询问', '是否确认提取报表数据?', function (index) {
                zlContext.post(layui.cache['contentPath'] + '/manager/coreauditreport/initreportdata', params, function (result) {
                    if (result[statusName] == OK) {
                        zlContext.successMsg('提数成功');
                        // gFrReportIframe.contentWindow.contentPane.refreshAllSheets();
                        gFrReportIframe.contentWindow.contentPane.loadContentPane();
                        return true;
                    }
                    else {
                        zlContext.errorMsg(result[msgName]);
                    }
                });
                layer.close(index);
            });
        },
        submitReport: function(row){
            var row = gridAction.currentEditObj.data;
            var params = {
                "RWID":row["RWID"]
            }
            zlContext.confirm('询问', '是否要确定提交报表送审?', function (index) {
                zlContext.post(layui.cache['contentPath'] + '/manager/coreauditreport/zgsubmit', params, function (result) {
					if (result[statusName] == OK) {
                        zlContext.successMsg('提交成功');
                        gridAction.currentEditObj.update(result[dataName]);
                        $.extend(gridAction.currentEditObj.data,result[dataName]);
                        gridAction.orgtreeObj.selectNode(gridAction.orgtreeObj.getNodes()[0]);
                        $('#' + gridAction.orgtreeObj.getNodes()[0].tId + '_a').click();
						return true;
					}
					else {
						zlContext.errorMsg(result[msgName]);
					}
				});
                layer.close(index);
            });
        },
        auditReport: function(args){
            var auditReportAction = {
                curLayerIndex: undefined,
                render: function(params){
                    var html = ['<form class="layui-form " style="margin:8px" id="addnew" lay-filter="audit-report-fw-form">'
                                , '   <div class="layui-form-item">'
                                , '       <div class="layui-col-md12 ">'
                                , '           <label class="layui-form-label">流程操作：</label>'
                                , '           <div class="layui-input-block">'
                                , '				   <input type="radio" id="canTongy" name="confirm" value="2" lay-filter="check" title="审核">'
                                , '				   <input type="radio" id="canTuih" name="confirm" value="3" lay-filter="check" title="退回">'
                                , '				   <input type="hidden" id="inputcanTongy" >'
                                , '				   <input type="hidden" id="inputcanTuih" >'     
                                , '           </div>'
                                , '       </div>'
                                , '   </div>'
                                , '   <div class="layui-form-item">'
                                , '       <div class="layui-col-md12">'
                                , '           <label class="layui-form-label">审批意见：</label>'
                                , '           <div class="layui-input-block">'
                                , '               <textarea class="layui-textarea" lay-filter="comment" maxlength="255" name="comment" style="width:90%"></textarea>'
                                , '           </div>'
                                , '       </div>'
                                , '   </div>'
                                , '   <div class="layui-form-btn-box">'
                                , '       <button class="layui-btn" id="btnadd" lay-submit  lay-filter="updateprocess" style="">提交</button>'
                                , '       <button class="layui-btn layui-btn-primary" id="btnAuditCancel">取消</button>'
                                , '   </div>'
                                , '</form>'
                                ];
                    auditReportAction.curLayerIndex = layer.open(
                        {
                            type: 1,
                            id: 'auditFwReportLayer',
                            content: html.join(""),
                            title: "流程审核",
                            area:'600px',
                            success: function (index) { 
                                form.render(null, 'audit-report-fw-form');
                                auditReportAction.setcommit(params);
                                $("#auditFwReportLayer").on("click","#btnAuditCancel", function(){
                                    layer.close(auditReportAction.curLayerIndex);
                                    return false;
                                });
                            }
                        });
                },
                setcommit: function (params) {
                    form.on('submit(updateprocess)', function (data) {
                        if(data.field.confirm==undefined){
                            zlContext.errorMsg('请选择相应的流程操作！');
                            return false;
                        }
                        var param ={
                            "comment":data.field.comment,
                            "confirm": data.field.confirm,
                            "ORG_RWID": gridAction.curOrgNodeReport["RWID"],
                            "ZG_RWID":gridAction.currentEditObj.data["RWID"]
                        }; 
                        if(gridAction.curOrgTreeNode && gridAction.curOrgTreeNode.isParent){
                            param = $.extend(param,{"zl_flag": "1"});
                        }else{
                            param = $.extend(param,{"zl_flag": "0"});
                        }
                        var url= layui.cache['contentPath'] + "/manager/coreauditreport/audit";           
                        zlContext.post(url, param, function (data) {
                            if (OK == data[statusName]) {
                                zlContext.successMsg('流程审核成功!');
                                var retData = data[dataName];
                                nodeReportAuditStatus[retData["ORGID"]] = retData["SYS_AUDFLAG"];
                                gridAction.orgtreeObj.selectNode(gridAction.curOrgTreeNode);
                                $('#' + gridAction.curOrgTreeNode.tId + '_a').click();
                                layer.close(auditReportAction.curLayerIndex);
                            }else{
                                zlContext.errorMsg(data[msgName]);
                            }
                        });
                        return false;
                    });
    
                    form.on('radio(check)', function (data) {
                        //可添加相应处理
                    });
                }
            }
            auditReportAction.render(reportAction.curOrgNodeReport);
        },
        backReport: function(args){
            var row = gridAction.curOrgNodeReport;
            var params = {
                "RWID":row["RWID"]
            }
            zlContext.confirm('询问', '确认退回该报表吗?', function (index) {
                zlContext.post(layui.cache['contentPath'] + '/manager/coreauditreport/back', params, function (result) {
					if (result[statusName] == OK) {
                        zlContext.successMsg('退回成功');
                        var retData = result[dataName];
                        nodeReportAuditStatus[retData["ORGID"]] = retData["SYS_AUDFLAG"];
                        gridAction.orgtreeObj.selectNode(gridAction.curOrgTreeNode);
                        $('#' + gridAction.curOrgTreeNode.tId + '_a').click();
						return true;
					}
					else {
						zlContext.errorMsg(result[msgName]);
					}
				});
                layer.close(index);
            });
        },
        writeState: function(state){

        }
    }
    //全局函数，报表保存成功的回调
    window.zlFrReportWriteSuccess = function(state){
		reportAction.writeState(state);
    }
     //全局函数，报表加载时用于设置请求参数
     window.setZlReportArgments = function(args){
        if(args){
            zlReportArgments = $.extend(zlReportArgments, args);
        }
    }
    //全局函数：获取报表对象
    window.getZlReport = function(){
        return gridAction.currentEditObj.data;
    }
	//监听行工具事件
	table.on('tool(tbDirectorReport)', function (obj) {
		var row = obj.data, //获得当前行数据
            layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            
		if (layEvent === 'edit-report') { //填报按钮
			gridAction.currentEditObj = obj;
			gridAction.editRow(row);
		}
    });
	//监听刷新的事件
	layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.REFRESHDATA_DATA, null, function (node) {
		var index = layer.msg('数据查询中，请稍候', {
			icon: 16,
			time: false,
			shade: 0.1
		});
		var loadGridData = function (id, url, param) {
			tableObj.reload({
				url: url,
				method: 'post',
				where: param,
				done: function (res, curr, count) {
					layer.close(index);
				}
			}, true);
		}
		var params = {
            "ORGID": curUserVo['currentOrgId']
        };
		
		loadGridData('tbDirectorReport', layui.cache['contentPath'] + '/manager/coreauditreport/reportlist', params);
    });
    
    //iframe自适应
    //控制高度的设置
	function setMaxHeihgt(deff, deff1) {
		$('.docking-left').height($(window).height() - deff);
		$('.docking-fill').height($(window).height() - deff);
		var treeHeaderH = $('.zltree-header').height();
        $('.layui-card-body').height($(window).height() - deff1);
        $('#coreZgReportLayer .docking-fill').height($("#coreZgReportLayer").height() - deff);
        $('#coreZgReportLayer .layui-card-body').height($('#coreZgReportLayer .docking-fill').height() - deff1);
        $("#coreZgReportLayer .zl-container").height($('#coreZgReportLayer .layui-card-body').height() - deff1);
        $('.zltree-body').height($('.layui-card-body').height() - treeHeaderH - 20);
        $('#coreZgReportLayer .docking-left').height($('#coreZgReportLayer .docking-fill').height());
        $('#coreZgReportLayer .layui-card.docking-left').height($('#coreZgReportLayer .docking-fill').height() - deff);
        $("#coreZgReportLayer .zltree-body").height($('#coreZgReportLayer .layui-card.docking-left').height() - treeHeaderH - 60);
    }
	$(window).on('resize', function () {
		//控制高度的设置
		setMaxHeihgt(10,30);
    }).resize();
});